package bm.com.project.server.organization.controller;

import bm.com.framework.common.config.EnumRoute;
import bm.com.project.server.VerifyController;
import bm.com.project.server.organization.entity.BmOrgEntity;
import bm.com.project.server.organization.service.OrgService;
import bm.com.framework.common.resp.PageVO;
import bm.com.framework.common.resp.Result;
import bm.com.framework.common.resp.ResultVO;
import bm.com.framework.common.unit.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//@Api("组织架构")
@RestController
@RequestMapping(EnumRoute.OrgRoute.Base)
public class OrgController extends VerifyController {

    @Autowired
    OrgService orgService;

    /**
     * 获取列表
     *
     * @return
     */
    @PostMapping(EnumRoute.OrgRoute.Org.LIST)
    public ResultVO getOrgList() {
        PageVO<List> orgList = orgService.getOrgList(this.getUserId());
        return ResultVO.success(orgList);
    }

    /**
     * 获取详情
     *
     * @param orgId
     * @return
     */
    @PostMapping(EnumRoute.OrgRoute.Org.DETAIL)
    public Result<BmOrgEntity> getOrgDetail(@RequestParam(name = "orgId") String orgId) {
        if (Tool.isStringEmpty(orgId)) {
            return new Result<BmOrgEntity>().error("组织唯一标识，不能为空");
        }
        return orgService.getOrgDetail(orgId);
    }

}
